/*
 * @(#)MapUtil.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.util;

import java.util.Map;

/**
 * @author Web Platform Development Team.
 */
public class MapUtil {
	
	/**
	 * Gets the string.
	 * 
	 * @param dataMap the data map
	 * @param parameterName the parameter name
	 * 
	 * @return the string
	 */
	public static String getString(Map<?, ?> dataMap, String parameterName) {
		if (parameterName == null) {
			return null;
		}

        if (dataMap == null) {
			return null;
		}
		
		Object element = dataMap.get(parameterName);
		return element == null ? null : (String)element;
	}

    /**
	 * Gets the string.
	 *
	 * @param dataMap the data map
	 * @param parameterName the parameter name
	 *
	 * @return the string
	 */
	public static String getActionString(Map<?, ?> dataMap, String parameterName) {
		if (parameterName == null) {
			return null;
		}

        if (dataMap == null) {
			return null;
		}

		Object element = dataMap.get(parameterName);
        
        if (element == null) {
            return null;
        }

        if (element instanceof String) {
            return (String)element;
        }

        if (element instanceof String[]) {
            return ((String[])element)[0];
        }

        return null;
    }
}
